﻿using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ConvertServerNet.Test
{
    [TestClass]
    public class WorkerUnitTest
    {
        [TestMethod]
        public void ParseFileNameSuccess()
        {
            var value = "1007-01-02-003-014-02-3-4-009-130712142536-6";
            var result = ConvertWorker.ParseFileName(value);
            Assert.AreEqual("1007", result.LocationNo);
            Assert.AreEqual("01", result.DirectionNo);
            Assert.AreEqual(2, result.LaneNo);

            var time = new DateTime(2013, 7, 12, 14, 25, 36);
            Assert.AreEqual(time, result.CaptureTime);
            Assert.AreEqual("192.168.3.14", result.Ip);
            Assert.AreEqual(9, result.GroupNo);
            Assert.AreEqual(6, result.SequenceNo);
        }

        [TestMethod]
        public void ParseGroupSameGroupDifferentTime()
        {
            var fileGroups = new string[]
            {
                @"c:\abc\def\1007-01-02-003-014-02-3-4-009-130712142536-6.jpg",
                "1007-01-02-003-014-02-3-4-009-130712142537-6.jpg",
                "1007-01-02-003-014-02-3-4-009-130712143536-6.jpg"
            };

            var groups = ConvertWorker.ParseFiles(fileGroups).ToList();
            Assert.AreEqual(2, groups.Count);
            Assert.AreEqual(2, groups[0].Length);
            Assert.AreEqual(@"c:\abc\def\1007-01-02-003-014-02-3-4-009-130712142536-6.jpg", groups[0][0].Item2);
            Assert.AreEqual(new DateTime(2013,7,12,14,25,36), groups[0][0].Item1.CaptureTime);
            Assert.AreEqual("1007-01-02-003-014-02-3-4-009-130712142537-6.jpg", groups[0][1].Item2);
            Assert.AreEqual(new DateTime(2013, 7, 12, 14, 25, 37), groups[0][1].Item1.CaptureTime);
            Assert.AreEqual(1, groups[1].Length);

        }

        [TestMethod]
        public void ParseGroupDifferentGroup()
        {
            var fileGroups = new string[]
            {
                "1007-01-02-003-014-02-3-4-009-130712142536-6",
                "1008-01-02-003-014-02-3-4-009-130712142537-6",
                "1009-01-02-003-014-02-3-4-009-130712143536-6"
            };

            var groups = ConvertWorker.ParseFiles(fileGroups).ToList();
            Assert.AreEqual(3, groups.Count);
            Assert.AreEqual(1, groups[0].Length);
            Assert.AreEqual(1, groups[1].Length);
            Assert.AreEqual(1, groups[2].Length);
        }
    }
}
